﻿using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Collections.Generic;
using System.Text.Json.Serialization;
using System.Windows.Documents;
using JsonIgnoreAttribute = Newtonsoft.Json.JsonIgnoreAttribute;

namespace SQLDataUploadHelper.models
{
    /// <summary>
    /// 上送响应
    /// </summary>
    internal class UploadResponse
    {
        /// <summary>
        /// 结果
        /// </summary>
        [JsonProperty(PropertyName = "result")]
        public string? Result { get; set; }

        /// <summary>
        /// 结果描述
        /// </summary>
        [JsonProperty(PropertyName = "message")]
        public JObject? Message { get; set; }

        /// <summary>
        /// 返回处理信息
        /// </summary>
        [JsonProperty(PropertyName = "returnValue")]
        public UploadRespContent? ReturnValue { get; set; }

        /// <summary>
        /// 是否错误
        /// </summary>
        [JsonProperty(PropertyName = "error")]
        public bool? Error { get; set; }

        /// <summary>
        /// 是否成功
        /// </summary>
        [JsonProperty(PropertyName = "success")]
        public bool? Success { get; set; }

        [JsonIgnore]
        public object? Throwable { get; set; }

        [JsonIgnore]
        public int? ErrCode { get; set; }

        [JsonIgnore]
        public object? ErrCause { get; set; }

        [JsonIgnore]
        public object? ErrExtraData { get; set; }

        /// <summary>
        /// 格式化
        /// </summary>
        /// <param name="response"></param>
        /// <returns></returns>
        public static UploadResponse parse(string response)
        {
            return JsonConvert.DeserializeObject<UploadResponse>(response);
        }
    }
}
/*{
    "result": "1",
    "message": {},
    "returnValue": {
        "tableName": "xxx",
        "ids": [
            "id1",
            "id2"
        ]
    },
    "throwable": null,
    "errCode": 0,
    "errCause": null,
    "errExtraData": null,
    "error": false,
    "success": true
}*/